package com.atguigu.service.impl;

import com.atguigu.dao.ItemInfoMapper;
import com.atguigu.pojo.ItemInfo;
import com.atguigu.service.ItemInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author LiChaochao
 * @Date 2021/9/27 19:14
 * @Description
 */
@Service
public class ItemInfoServiceImpl implements ItemInfoService {

    @Autowired
    private ItemInfoMapper itemInfoMapper;

    /**
     * 库存递减
     * @param id
     * @param count
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void decrCount(int id, int count) {
        ItemInfo itemInfo = itemInfoMapper.selectByPrimaryKey(id);
        itemInfo.setCount(itemInfo.getCount() - count);
        int i = itemInfoMapper.updateByPrimaryKeySelective(itemInfo);
        System.out.println("受影响的行数i = " + i);
    }
}
